<template>

  <div class='couponPurchaseBox'>
    <div class='couponBox'>
      <el-breadcrumb class='topBox' separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/order/transfer' }">用户意见反馈</el-breadcrumb-item>
      </el-breadcrumb>

      <div class='couponPurchase'>
        <el-table  :data="tableData" border style="width: 100%">
          <el-table-column label="用户Id">
            <template slot-scope="scope">
                <!-- <img :src="users[scope.row.userId].avatar" alt=""> -->
            <span>{{users[scope.row.userId].userId}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="content" label="反馈内容">
          </el-table-column>
          <el-table-column label="反馈图片">
            <template slot-scope="scope">
              <img :src="item" alt="" v-for="(item,index) in scope.row.pictures" :key="index">
            </template>
          </el-table-column>
        <el-table-column label="反馈时间">
             <template slot-scope="scope">
              <span>{{changeTime(scope.row.createTime)}}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作">
             <template slot-scope="scope">
                 <span v-if="scope.row.reply">已处理</span>
              <span @click="solution(scope.row)" style="cursor:pointer;color:rgb(71, 158, 238)" v-else>处理</span>
            </template>
          </el-table-column>
        </el-table>
        <div class='paginationBox'>
          <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                         :current-page="1" :page-sizes="[10,20,30,50]" :page-size="listQuery.limit"
                         layout="total, sizes, prev, pager, next, jumper" :total="total">
          </el-pagination>
        </div>
      </div>
    </div>
      <el-dialog title="提示" :visible.sync="dialogTableVisible">
            <h3 style="text-align:center">确认处理？</h3>
        <div slot="footer" class="dialog-footer">
            <el-button @click="cannel">取 消</el-button>
            <el-button type="primary" @click="confirm">确 定</el-button>
        </div>
        </el-dialog>
  </div>
</template>


<script>
  import { getToken } from '@/utils/auth';
  import { feedbackList,feedbackReply} from '@/api/feedback.js';
  import { showDecimal,parseTime } from '@/utils'

  export default {
    data() {
      return {
        user:{},
        text:'',
        dialogTableVisible:false,
        options: [],
        total:0,
        users:{},
        tableData: [],
        listQuery:{
          page:0,
          limit:10,
          token:getToken(),
        }
      }
    },
    methods: {
        cannel(){
            this.user={};
            this.text='';
            this.dialogTableVisible=false;
        },
        confirm(){
            this.changeStatus();
        },
        solution(row){
            this.user=row;
            this.dialogTableVisible=true;
        },
      changeTime(time){
        return parseTime(time)
      },
      getData(){
        feedbackList(this.listQuery).then(res=>{
          if(res.status==200&&res.data){
            this.total=res.total
            this.tableData=res.data
            this.users=res.users
          }
        })
      },
      changeStatus(){
          let params={
              feedbackId:this.user.id,
              reply:this.text||'ignore',
              token:getToken()
          }
        feedbackReply(params).then(res=>{
          if(res.status==200){
            this.text='';
            this.user={};
            this.dialogTableVisible=false;
          }
        })
      },
      handleSizeChange(val) {
        this.listQuery.limit = val
        this.getData()
      },
      handleCurrentChange(val) {
        this.listQuery.page = val - 1
        this.getData()
      }
    },
    mounted(){
      this.getData()
    }
  }

</script>

<style lang="scss">
 .el-table__row td:nth-of-type(1) .cell{
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            img{
                width:50px;
                height:50px;
                border-radius: 50%;
            }
    }
.el-table__row td:nth-of-type(3) .cell{
    display: flex;
    justify-content: space-around;
    img{
        width:50px;
        height:50px;
    }
}
</style>


<style lang="scss" scoped>
  .couponPurchaseBox {
    margin-top: 32px;

    .couponBox {
      width: 90%;
      margin: 0 auto;

      .topBox {
        color: rgba(16, 16, 16, 1);
        font-size: 24px;
        margin-bottom: 50px;
      }

      .couponPurchase {
        margin-top: 52px;
        background: #fff;
        padding: 25px 29px;
        h3 {
          color: rgba(45, 45, 45, 1);
          font-size: 22px;
          margin-bottom: 19px;
          font-weight: 400;

          span:last-child {
            color: rgba(190, 26, 33, 1);
          }
        }

        .conditions {
          display: flex;
          justify-content: space-between;
          width: 41%;
          margin-bottom: 31px;
          align-items: center;

          .el-input {
            width: 28%;
          }
        }

        .paginationBox {
          text-align: right;
          margin-top: 60px;
        }



      }
    }
  }

</style>
